<html>
<head>
<title>Docs for page functions.db.php</title>
<link rel="stylesheet" type="text/css" href="../media/style.css">
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  <tr>
    <td class="header_top">smt2</td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
  <tr>
    <td class="header_menu">
        
                                    
                                                                      		  [ <a href="../classtrees_smt2.html" class="menu">class tree: smt2</a> ]
		  [ <a href="../elementindex_smt2.html" class="menu">index: smt2</a> ]
		  	    [ <a href="../elementindex.html" class="menu">all elements</a> ]
    </td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="200" class="menu">
      <b>Packages:</b><br />
              <a href="../li_smt2.html">smt2</a><br />
              <a href="../li_PegasusPHP.html">PegasusPHP</a><br />
              <a href="../li_PHPMailer.html">PHPMailer</a><br />
            <br /><br />
                        <b>Files:</b><br />
      	  <div class="package">
			<a href="../smt2/_class.cluster.php.html">		class.cluster.php
		</a><br>
			<a href="../smt2/_class.domutil.php.html">		class.domutil.php
		</a><br>
			<a href="../smt2/_class.kmeans.php.html">		class.kmeans.php
		</a><br>
			<a href="../smt2/_class.point.php.html">		class.point.php
		</a><br>
			<a href="../smt2/_class.prettydate.php.html">		class.prettydate.php
		</a><br>
			<a href="../smt2/_define.php.html">		define.php
		</a><br>
			<a href="../smt2/_functions.array.php.html">		functions.array.php
		</a><br>
			<a href="../smt2/_functions.db.php.html">		functions.db.php
		</a><br>
			<a href="../smt2/_functions.php.html">		functions.php
		</a><br>
			<a href="../smt2/_functions.url.php.html">		functions.url.php
		</a><br>
			<a href="../smt2/_messages.php.html">		messages.php
		</a><br>
	  </div><br />
      
      
            <b>Classes:</b><br />
        <div class="package">
		    		<a href="../smt2/Cluster.html">Cluster</a><br />
	    		<a href="../smt2/DOMUtil.html">DOMUtil</a><br />
	    		<a href="../smt2/KMeans.html">KMeans</a><br />
	    		<a href="../smt2/Point.html">Point</a><br />
	    		<a href="../smt2/prettyDate.html">prettyDate</a><br />
	  </div>
                </td>
    <td>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1>Procedural File: functions.db.php</h1>
Source Location: /functions.db.php<br /><br />

<br>
<br>


<h2>Page Details:</h2>
This class is a wrapper layer for all required MySQL queries.<br /><br /><p>It is highly recommended to use them instead of the current PHP functions,  because in that way it is possible to abstract this layer  and use different database engines.</p><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>filesource:</b>&nbsp;&nbsp;</td><td><a href="../__filesource/fsource_smt2__functions.db.php.html">Source Code for this file</a></td>
  </tr>
</table>
</div>
<br /><br />
<br /><br />
<br /><br />
<br />
  <hr />
	<a name="functiondb_check"></a>
	<h3>db_check <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a126">126</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>boolean db_check(
)</code>
    </td></tr></table>
    </td></tr></table><br />

		Checks that both database connection and tables are OK.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>TRUE on sucess, or FALSE on failure</td>
  </tr>
</table>
</div>
    <br /><br />
	
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_connect"></a>
	<h3>db_connect <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a17">17</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>resource db_connect(
)</code>
    </td></tr></table>
    </td></tr></table><br />

		Opens or reuses a connection against the database server.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>connection link identifier</td>
  </tr>
</table>
</div>
    <br /><br />
	
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_delete"></a>
	<h3>db_delete <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a84">84</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>boolean db_delete(
string $table, string $condition)</code>
    </td></tr></table>
    </td></tr></table><br />

		Deletes a row from table.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>TRUE on success, or FALSE on failure</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$table</b>&nbsp;&nbsp;</td>
        <td>able name</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$condition</b>&nbsp;&nbsp;</td>
        <td>WHERE clause (i.e: id='#' LIMIT 1)</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_insert"></a>
	<h3>db_insert <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a99">99</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>int db_insert(
string $table, string $fields, string $values)</code>
    </td></tr></table>
    </td></tr></table><br />

		Inserts a new row on table.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>last instered row id, or FALSE on failure</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$table</b>&nbsp;&nbsp;</td>
        <td>table name</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$fields</b>&nbsp;&nbsp;</td>
        <td>column(s) name(s)</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$values</b>&nbsp;&nbsp;</td>
        <td>column(s) value(s)</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_option"></a>
	<h3>db_option <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a172">172</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>string db_option(
string $table, string $optionName)</code>
    </td></tr></table>
    </td></tr></table><br />

		Selects one (and only one) row from an &quot;options&quot; table (CMS or JSOPT).<br /><br /><p>This function is a wrapper for 'db_select()'.  Instead of having to deal with an associative array of one key alone,  this function speeds the process and returns the array member value.</p><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>Option value</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$table</b>&nbsp;&nbsp;</td>
        <td>table name</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$optionName</b>&nbsp;&nbsp;</td>
        <td>option name stored on &quot;name&quot; column</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_query"></a>
	<h3>db_query <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a30">30</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>resource db_query(
string $sql)</code>
    </td></tr></table>
    </td></tr></table><br />

		Performs a generic query to database.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>Resource query identifier</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$sql</b>&nbsp;&nbsp;</td>
        <td>SQL query</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_records"></a>
	<h3>db_records <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a145">145</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>mixed db_records(
[boolean $getColNames = false])</code>
    </td></tr></table>
    </td></tr></table><br />

		Shortcut for getting the total number of (smt) records in database, or alternatively the column names.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>Number of total DB entries (int) or column names (array)</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">boolean&nbsp;&nbsp;</td>
        <td><b>$getColNames</b>&nbsp;&nbsp;</td>
        <td>return column names instead of number of records</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_select"></a>
	<h3>db_select <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a46">46</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>mixed db_select(
string $table, string $column, string $condition)</code>
    </td></tr></table>
    </td></tr></table><br />

		Gets column(s) value(s) of a single row from a table.<br /><br /><p>This function can be used also to check if a row field exists.</p><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>Associative array with column(s) name(s) as keys on success or FALSE on failure</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$column</b>&nbsp;&nbsp;</td>
        <td>column(s) name(s)</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$table</b>&nbsp;&nbsp;</td>
        <td>table name</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$condition</b>&nbsp;&nbsp;</td>
        <td>WHERE condition. To allow row ordering without WHERE clause, you can use &quot;1 ORDER BY ...&quot;</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_select_all"></a>
	<h3>db_select_all <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a64">64</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>array db_select_all(
string $table, string $column, string $condition)</code>
    </td></tr></table>
    </td></tr></table><br />

		Selects ALL rows and columns from table that match the given condition.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>Array with all queried rows.</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$table</b>&nbsp;&nbsp;</td>
        <td>table name</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$column</b>&nbsp;&nbsp;</td>
        <td>column name</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$condition</b>&nbsp;&nbsp;</td>
        <td>WHERE condition. To allow row ordering without WHERE clause, you can use &quot;1 ORDER BY ...&quot;</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>
  <hr />
	<a name="functiondb_update"></a>
	<h3>db_update <span class="smalllinenumber">[line <a href="../__filesource/fsource_smt2__functions.db.php.html#a114">114</a>]</span></h3>
	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
		<code>boolean db_update(
string $table, string $tuples, string $condition)</code>
    </td></tr></table>
    </td></tr></table><br />

		Updates a row on table.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><b>return:</b>&nbsp;&nbsp;</td><td>TRUE on success, or FALSE on failure</td>
  </tr>
</table>
</div>
    <br /><br />
	
    		<h4>Parameters</h4>
    <table border="0" cellspacing="0" cellpadding="0">
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$table</b>&nbsp;&nbsp;</td>
        <td>table name</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$tuples</b>&nbsp;&nbsp;</td>
        <td>column(s) name(s) and value(s) in the form column=value (i.e: col='val',foo='val',...)</td>
      </tr>
		      <tr>
        <td class="type">string&nbsp;&nbsp;</td>
        <td><b>$condition</b>&nbsp;&nbsp;</td>
        <td>WHERE clause (i.e: id='#' LIMIT 1)</td>
      </tr>
				</table>
    	<div class="top">[ <a href="#top">Top</a> ]</div><br /><br />
	</div>

        <div class="credit">
		    <hr />
		    Documentation generated on Thu, 30 Sep 2010 18:26:49 +0200 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.1</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
</table>

</body>
</html>